#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2.6e5 + 5;

int n;
struct Node {
  int x, y, m, p, r;
  ll d;
} a[N];
bool cmpm(const Node& a, const Node& b) { return a.m < b.m; }
bool cmpd(const Node& a, const Node& b) { return a.d < b.d; }
int bid[N], l[505], r[505], pos[505];
int m[N], vis[N];
ll d[N];
void init() {
  int k = sqrt(n);
  rep(i, 1, n) bid[i] = (i - 1) / k + 1;
  int bcnt = bid[n];
  sort(a + 1, a + n + 1, cmpm);  // 全局 按质量大小排序
  rep(i, 1, n) m[i] = a[i].m;
  rep(i, 1, bcnt) {
    l[i] = (i - 1) * k + 1, r[i] = i * k;
    pos[i] = l[i];
  }
  r[bcnt] = n;
  rep(i, 1, bcnt) sort(a + l[i], a + r[i] + 1, cmpd);
  rep(i, 1, n) d[i] = a[i].d;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> a[0].x >> a[0].y >> a[0].p >> a[0].r;
  cin >> n;
  rep(i, 1, n) {
    cin >> a[i].x >> a[i].y >> a[i].m >> a[i].p >> a[i].r;
    int dx = a[i].x - a[0].x, dy = a[i].y - a[0].y;
    a[i].d = 1ll * dx * dx + 1ll * dy * dy;
  }
  init();
  queue<pii> q;
  q.push(pii(a[0].p, a[0].r));
  while (q.size()) {
    int p = q.front().first, radius = q.front().second;
    q.pop();
    int R = upper_bound(m + 1, m + n + 1, p) - m - 1;
    int id = bid[R];
    ll r2 = 1ll * radius * radius;
    rep(i, 1, id - 1) {
      while (pos[i] <= r[i] && a[pos[i]].d <= r2) {
        if (!vis[pos[i]]) {
          q.push(pii(a[pos[i]].p, a[pos[i]].r));
          vis[pos[i]] = 1;
        }
        pos[i]++;
      }
    }
    rep(i, l[id], r[id]) {
      if (!vis[i] && a[i].m <= p && a[i].d <= 1ll * radius * radius) {
        q.push(pii(a[i].p, a[i].r));
        vis[i] = 1;
      }
    }
  }
  int ans = 0;
  rep(i, 1, n) ans += vis[i];
  cout << ans;
  return 0;
}